<template>
  <div class="container">
    <div class="container-title">
      <p>投诉建议</p>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>社区服务</el-breadcrumb-item>
        <el-breadcrumb-item>投诉建议</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="search-box">
      <el-form ref="form" :model="searchData">
        <el-form-item
          ><el-input
            v-model="searchData.complainant"
            placeholder="投诉人"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="searchData.contactNumber"
            placeholder="联系电话"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="searchData.suggestionType"
            filterable
            placeholder="建议类型"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="searchData.state" filterable placeholder="状态">
            <el-option
              v-for="item in options1"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <div class="block">
          <el-date-picker
            v-model="searchData.date"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </div>
        <el-form-item>
          <el-button
            type="success"
            @click="onSearch"
            icon="el-icon-search"
            style="background-color: #0bb197"
            >查询</el-button
          ><el-button @click="onReset" icon="el-icon-refresh" class="reset"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <!-- 表格 -->
    <div class="data-list">
      <div class="data-list-title">
        <span>查询结果列表</span>
      </div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="complaintsId" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="suggestionType" label="建议类型" align="center">
        </el-table-column>
        <el-table-column
          prop="suggestedContent"
          label="建议内容"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="suggestedTime" label="建议时间" align="center">
          <template slot-scope="scope">
            {{ timeTrans(scope.row.suggestedTime, 0) }}
          </template>
        </el-table-column>
        <el-table-column prop="complainant" label="投诉人" align="center">
        </el-table-column>
        <el-table-column prop="contactNumber" label="联系电话" align="center">
        </el-table-column>
        <el-table-column prop="state" label="状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.state == 0">待受理</span>
            <span v-if="scope.row.state == 1">待派单</span>
            <span v-if="scope.row.state == 2">待接单</span>
            <span v-if="scope.row.state == 3">处理中</span>
            <span v-if="scope.row.state == 4">已完成</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="200">
          <template slot-scope="scope">
            <el-button @click="detail(scope.row)" type="text" size="small"
              >详情</el-button
            >
          </template></el-table-column
        >
      </el-table>
      <!-- 页码 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :background="true"
      >
      </el-pagination>
    </div>
    <!-- 详情信息弹窗 -->
    <el-dialog
      title="详细信息"
      :visible.sync="detailDialog"
      width="43%"
      class="detail"
    >
      <div class="detail-information1">
        <p class="suggestionType">
          建议类型：{{ detailData[0].complaintsSuggestions.suggestionType }}
        </p>
        <p class="suggestedContent">
          建议内容：{{ detailData[0].complaintsSuggestions.suggestedContent }}
        </p>
      </div>
      <div class="detail-information2">
        <p class="suggestedTime">
          建议时间：{{
            timeTrans(detailData[0].complaintsSuggestions.suggestedTime, 0)
          }}
        </p>
        <p class="complainant">
          投诉人： {{ detailData[0].complaintsSuggestions.complainant }}
        </p>
      </div>
      <div class="detail-information3">
        <p class="tel">
          联系电话：{{ detailData[0].complaintsSuggestions.contactNumber }}
        </p>
      </div>
      <div class="detail-table">
        <div class="table-title">流程记录：</div>
        <el-table :data="detailData">
          <el-table-column
            property="romplaintId"
            label="序号"
            align="center"
          ></el-table-column>
          <el-table-column property="operation" label="操作" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.operation == 0">发起投诉</span>
              <span v-if="scope.row.operation == 1">受理</span>
              <span v-if="scope.row.operation == 2">处理完成</span>
            </template>
          </el-table-column>
          <el-table-column
            property="operator"
            label="操作人"
            align="center"
          ></el-table-column>
          <el-table-column
            property="operationTime"
            label="操作时间"
            align="center"
          >
            <template slot-scope="scope">
              {{ timeTrans(scope.row.operationTime, 0) }}
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import time from '../utils/time';
export default {
  mixins: [time],
  data: function () {
    return {
      pageNum: 1,
      pageSize: 5,
      total: 0,
      currentPage: 1,
      options: [
        {
          value: '卫生投诉',
          label: '卫生投诉',
        },
        {
          value: '物业投诉',
          label: '物业投诉',
        },
      ],

      options1: [
        {
          value: 0,
          label: '待受理',
        },
        {
          value: 1,
          label: '待派单',
        },
        {
          value: 2,
          label: '待接单',
        },
        {
          value: 3,
          label: '处理中',
        },
        {
          value: 4,
          label: '已完成',
        },
      ],
      //搜索
      searchData: {
        complainant: '',
        contactNumber: '',
        suggestionType: '',
        date: [],
        state: '',
      },
      tableData: [],
      // 详情信息弹窗
      detailDialog: false,
      detailData: [
        {
          romplaintId: 0,
          operation: '',
          operator: '',
          operationTime: 0,
          complaintsSuggestions: {
            complaintsId: 0,
            suggestionType: '',
            suggestedContent: '',
            suggestedTime: 0,
            state: 0,
            complainant: '',
            contactNumber: '',
            isDelete: 0,
          },
          isDelete: 0,
        },
      ],
    };
  },
  methods: {
    //渲染
    getData: function () {
      this.$axios({
        url:
          '/smart/complaints-suggestions/list/' +
          this.pageNum +
          '/' +
          this.pageSize,
      }).then(({ data }) => {
        if (data.code == '00000') {
          this.tableData = data.data.pageInfo.list;
          this.total = data.data.pageInfo.total;
        } else {
          this.$message.error(data.msg);
        }
      });
    },
    //搜索
    onSearch: function () {
      this.$axios({
        url: '/smart/complaints-suggestions/search',
        method: 'post',
        params: {
          pageNum: 1,
          pageSize: this.pageSize,
        },
        data: {
          complainant: this.searchData.complainant,
          contactNumber: this.searchData.contactNumber,
          startTime: this.searchData.date[0],
          endTime: this.searchData.date[1],
          state: Number(this.searchData.state),
          suggestionType: this.searchData.suggestionType,
        },
      }).then(({ data }) => {
        if (data.code == '00000') {
          if (data.data.pageInfo.list.length > 0) {
            this.tableData = data.data.pageInfo.list;
          } else {
            this.tableData = data.data.pageInfo.list;
            this.$message.error('暂无数据！');
          }
        } else {
          this.$message.error(data.msg);
        }
      });
    },
    onReset: function () {
      this.searchData = {
        complainant: '',
        contactNumber: '',
        suggestionType: '',
        date: [],
        state: '',
      };
      this.getData();
    },
    //详情
    detail: function (row) {
      this.detailDialog = true;
      this.$axios({
        url: '/smart/romplaint-record/list/' + row.complaintsId,
      }).then(({ data }) => {
        if (data.code == '00000') {
          data.data.forEach((v, i) => {
            v.romplaintId = i + 1;
          });
          this.detailData = data.data;
        } else {
          this.$message.error(data.msg);
        }
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getData();
    },
  },
  mounted: function () {
    this.getData();
  },
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  .container-title {
    width: 98%;
    height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    p {
      color: #333333;
      font-size: 16px;
      font-weight: 400;
      font-family: 'Arial Normal', 'Arial';
    }
    .el-breadcrumb-item {
      color: rgba(148, 148, 148, 0.898039215686275);
      font-size: 12px;
      font-weight: 400;
      font-family: 'Arial Normal', 'Arial';
    }
  }
  .search-box {
    width: 98%;
    height: 80px;
    background: #ffffff;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    border: 1px solid #ffffff;
    border-radius: 5px;
    .el-form {
      width: 98%;
      background: #ffffff;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .el-form-item {
        margin-left: 10px;
        margin-bottom: 0;
        .el-select {
          width: 155px;
        }
        .el-button {
          margin: 10px;
        }
        .reset {
          background-color: white;
          color: #c0c4cc;
          border: 1px solid #c0c4cc;
        }
        .reset:hover {
          color: #0bb197;
        }
      }
      .block {
        margin-left: 10px;
      }
      .el-date-editor--datetimerange.el-input__inner {
        width: 310px;
      }
    }
  }
  .data-list {
    width: 98%;
    height: 100%;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    margin-top: 20px;
    .data-list-title {
      width: 98%;
      height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      span {
        height: 16px;
        font-family: 'Arial Normal', 'Arial';
        font-weight: 700;
        font-style: normal;
        font-size: 13px;
        color: #3c4145;
      }
    }
    .el-table {
      flex: 1;
      .el-button {
        color: #0bb197;
      }
    }
    .el-pagination {
      width: 98%;
      height: 60px;
      display: flex;
      justify-content: flex-end;
      align-items: center;
    }
  }
}
</style>
<style lang="less">
.el-pagination.is-background .el-pager li:not(.disabled):hover {
  color: #0bb197;
}
.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #0bb197;
  color: #fff;
}
// 详情信息弹窗
.detail .el-dialog {
  display: flex;
  flex-direction: column;
  align-items: center;
  .el-dialog__header {
    width: 100%;
    height: 47px;
    color: #ffffff;
    background: #0bb197;
    padding: 0;
    .el-dialog__title {
      line-height: 47px;
      font-size: 15px;
      color: #ffffff;
      margin-left: 20px;
    }
    .el-dialog__headerbtn .el-dialog__close {
      color: #ffffff;
    }
  }
  .el-dialog__body {
    width: 95%;
    height: 554px;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    .detail-information1 {
      width: 95%;
      height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .suggestionType {
        width: 60%;
        text-align: left;
      }
      .suggestedContent {
        width: 30%;
        text-align: left;
      }
    }
    .detail-information2 {
      width: 95%;
      height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .suggestedTime {
        width: 60%;
        text-align: left;
      }
      .complainant {
        width: 30%;
        text-align: left;
      }
    }
    .detail-information3 {
      width: 95%;
      height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .tel {
        width: 60%;
        text-align: left;
      }
    }
    .detail-table {
      width: 95%;
      flex: 1;
      .table-title {
        height: 60px;
        line-height: 60px;
      }
    }
  }
}
</style>
